package com.recSys.test;

import com.recSys.util.HttpClientHandler;
import net.sf.json.JSONObject;

import java.io.*;
import java.text.DecimalFormat;

/**
 * Created by dell on 2018/1/30.
 */
public class GetLocationParameter {
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("C:\\Users\\dell\\Desktop\\addr.txt")),"gbk"));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("C:\\Users\\dell\\Desktop\\addrLL.txt")),"UTF-8"));
        String lineTxt = null;
        while ((lineTxt = br.readLine()) != null) {
            System.out.println(lineTxt.trim());
            String res = HttpClientHandler.doGet(lineTxt.trim());
            JSONObject object = JSONObject.fromObject(res);
            JSONObject result= object.getJSONObject("result");
            JSONObject location = result.getJSONObject("location");
            DecimalFormat df = new DecimalFormat("0.00");
            String lng = location.getString("lng");
            String lat = location.getString("lat");
            bw.write(df.format(Double.parseDouble(lng))+"\t"+df.format(Double.parseDouble(lat)));
            bw.newLine();
        }
        br.close();
        bw.close();
    }
}
